package com.example.test.exam;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.example.test.R;
import com.example.test.all_Myhelper.exam_Myhelper;
import com.example.test.wrong.wrong_list;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class result extends AppCompatActivity implements View.OnClickListener {
    public exam_Myhelper exam_myhelper;
    public TextView result;
    public Button back,see_wrong;
    List<Integer> mark = new ArrayList<>();//记录错题的编号

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.result);
//        exam_myhelper = new exam_Myhelper(this);
        init();
        result.setText(String.valueOf(grade()));
        System.out.println("错题有："+mark);

    }

    public void init(){
        result = (TextView) findViewById(R.id.result);
        back = (Button) findViewById(R.id.back);
        see_wrong = (Button) findViewById(R.id.see_wrong);
        back.setOnClickListener(this);
        see_wrong.setOnClickListener(this);
    }

    public int grade(){//计算成绩，记录错题
        Bundle bundle = getIntent().getExtras();//获取ceshi传来的参数
        List<String> chance = bundle.getStringArrayList("chance");//测试时用户的选择列表
        List<Integer> id_list = bundle.getIntegerArrayList("id");
        List<String> daan_list = bundle.getStringArrayList("daan");
        System.out.println(chance+"...."+id_list+"...."+daan_list);
//        int i = 0;
//        SQLiteDatabase db;
//        db = exam_myhelper.getReadableDatabase();
//        Cursor cursor = db.query("tiku",null,null,null,null,null,null);
//        String[] daan = new String[cursor.getCount()];//daan——>list
//        Integer[] num = new Integer[cursor.getCount()];//num-->number
//        while (cursor.moveToNext()){
//            num[i] = cursor.getInt(0);
//            daan[i] = cursor.getString(6);
//            i++;
//        }
//        List<Integer> number = Arrays.asList(num);//记录每次测试的题目的编号
//        List<String> list = Arrays.asList(daan);//对应编号的答案
//        cursor.close();
//        db.close();
        System.out.println("zzzz"+id_list);
        int fenzhi = 100/id_list.size();
        int count = 100;
        System.out.println("--------");
        for(int j=0;j<id_list.size();j++){
            System.out.println(chance.get(j)+"----"+daan_list.get(j));
            if(!chance.get(j).equals(daan_list.get(j))){
                count = count - fenzhi;
                mark.add(id_list.get(j));
//                System.out.println(mark.get(j));
            }else{
                System.out.println("相等");
            }
        }
        return count;

    }

    @Override
    public void onClick(View v) {
        if(v.getId()==R.id.see_wrong) {
            Intent intent = new Intent(result.this, wrong_list.class);
            Bundle bundle = new Bundle();
            bundle.putIntegerArrayList("wrong_id", (ArrayList<Integer>) mark);
            intent.putExtras(bundle);
            startActivity(intent);
        }else if (v.getId()==R.id.back){
            Intent intent = new Intent(result.this, Main.class);
            startActivity(intent);

        }


    }
}